package produce_custom;

public class Produce extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (Tri_Person.lock){
                if (Tri_Person.count==0){
                    break;
                }else {
                    //有没有产品,没有就做;有就等待,唤醒消费者
                    if (Tri_Person.flag==0){
                        Tri_Person.flag=1;
                        System.out.println("生产者做了1个产品");
                        Tri_Person.lock.notifyAll();
                    }else if (Tri_Person.flag==1){
                        try {
                            Tri_Person.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }


                }
            }
        }
    }
}
